package com.example.ssm.service.impl;

import com.example.ssm.bean.Employee;
import com.example.ssm.bean.EmployeeExample;
import com.example.ssm.dao.EmployeeMapper;
import com.example.ssm.service.EmployeeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Intellij IDEA.
 * User: JonnyJiang
 * Date: 2021/6/5
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Resource
    EmployeeMapper employeeMapper;

    @Override
    public List<Employee> getAll() {
        return employeeMapper.selectByExampleWithDepName(null);
    }

    @Override
    public int addEmp(Employee employee) {
        return employeeMapper.insert(employee);
    }

    @Override
    public long hasUser(EmployeeExample employeeExample) {
        return employeeMapper.countByExample(employeeExample);
    }

    @Override
    public Employee getEmp(Integer id) {
        return employeeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateEmp(Employee employee) {
        return employeeMapper.updateByPrimaryKeySelective(employee);
    }

    @Override
    public int deleteEmp(Integer empId) {
        return employeeMapper.deleteByPrimaryKey(empId);
    }

    @Override
    public void deleteEmpBatch(List<Integer> ids) {
        EmployeeExample employeeExample = new EmployeeExample();
        EmployeeExample.Criteria criteria = employeeExample.createCriteria();
        criteria.andEmpIdIn(ids);
        employeeMapper.deleteByExample(employeeExample);
    }


}
